﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GSPatEditor.SoundEffect
{
    class SoundEffectResources
    {
        private readonly Dictionary<int, SoundEffect> soundEffects = new Dictionary<int, SoundEffect>();
        private readonly SoundEffect empty = new SoundEffect(null);

        public SoundEffectResources()
        {
        }

        public void AddPath(string path)
        {
            foreach (var file in Directory.GetFiles(path, "*.cv3", SearchOption.TopDirectoryOnly))
            {
                int name;
                if (Int32.TryParse(Path.GetFileNameWithoutExtension(file), out name))
                {
                    soundEffects[name] = new SoundEffect(file);
                }
            }
        }

        public SoundEffect GetSoundEffectByName(int name)
        {
            if (soundEffects.ContainsKey(name))
            {
                return soundEffects[name];
            }
            else
            {
                return empty;
            }
        }
    }
}
